import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:can/classes/app_colors.dart';
import 'package:can/screens/game.dart';
import 'package:can/widgets/home/choose_color_dropdown.dart';
import 'package:can/widgets/text_input_box.dart';

class StartGamePopup extends StatelessWidget {
  const StartGamePopup({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
        title: const Text("Enter players' names"),
        content: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: const [
                TextInputBox(hintText: "玩家 1"),
                TextInputBox(hintText: "玩家 2")
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: const [
                Expanded(child: Center(child: ChooseColorDropDown())),
                Expanded(child: Center(child: ChooseColorDropDown())),
              ],
            )
          ],
        ),
        actions: <Widget>[
          Row(
            children: [
              Expanded(
                child: Align(
                  alignment: Alignment.bottomLeft,
                  child: TextButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                    child: const Text('Cancel',
                        style: TextStyle(color: AppColors.purple)),
                  ),
                ),
              ),
              Expanded(
                child: Align(
                  alignment: Alignment.bottomRight,
                  child: TextButton(
                    onPressed: () {
                      Navigator.of(context).pop();
                      Navigator.push(
                        context,
                        MaterialPageRoute(builder: (context) => const Game()),
                      );
                    },
                    child: const Text(
                      'Start Game!',
                      style: TextStyle(color: AppColors.purple),
                      textAlign: TextAlign.right,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ]);
  }
}

class RulesPopup extends StatelessWidget {
  const RulesPopup({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text(
        '玩法规则',
        textAlign: TextAlign.center,
      ),
      content: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: const <Widget>[
            Text(
                "CanWords是一个字母组合游戏，两名玩家通过在分成15×15方格的棋盘上放置字母，使得其中相连的方块组成单词完成游戏。",
                textAlign: TextAlign.justify),
            Text("\n玩法\n",
                style: TextStyle(
                    color: Color.fromARGB(255, 203, 83, 207),
                    fontWeight: FontWeight.bold)),
            Text("1. 第一个玩家将两个或两个以上的字母放到方块中，组合一个单词\n",
                textAlign: TextAlign.justify),
            Text("2. 玩家通过点击“完成提交”按钮来完成他们的回合。如果玩家想不出单词，也可以放弃本轮不放置字母\n",
                textAlign: TextAlign.justify),
            Text("3. 每个玩家依次添加一个或多个字母，在一个回合中，组成至少一个完整的单词。",
                textAlign: TextAlign.justify),
          ],
        ),
      ),
      actions: <Widget>[
        TextButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: const Text("我知道了",
              style: TextStyle(color: Color.fromARGB(255, 224, 126, 233))),
        ),
      ],
    );
  }
}

class AuthorsPopup extends StatelessWidget {
  const AuthorsPopup({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('BabbleWords! was created by'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: const <Widget>[
          Text("Maciej Byczko"),
          Text("Filip Przygoński"),
          Text("Filip Sołdon"),
          Text("Jakub Tołściuk"),
        ],
      ),
      actions: <Widget>[
        TextButton(
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: const Text('Close', style: TextStyle(color: AppColors.purple)),
        ),
      ],
    );
  }
}
